package edu.ntnu.superrss.models;

import com.sun.syndication.feed.impl.CopyFromHelper;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.synd.SyndImage;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;

/**
 * This is a copy of SyndImageImpl in ROME with hibernate annotations
 * @author Sigurd Fosseng <sigurd at fosseng.net>
 */
@Entity
@Table(name="IMAGE")
public class SyndImageImpl implements SyndImage, Serializable{
	private ObjectBean objBean;
	private Long id;
	private String title;
	private String url;
	private String link;
	private String description;

      @Id
	@GeneratedValue
	@Column(name="IMAGE_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	public SyndImageImpl(){
		this.objBean = new ObjectBean(SyndImage.class, this);
	}

	@Override
	public Object clone() throws CloneNotSupportedException{
		return objBean.clone();
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String string) {
		this.title = string;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String string) {
		this.link = string;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String string) {
		this.description = string;
	}
	@Transient
	public Class getInterface() {
		return SyndImage.class;
	}

      //Utilizes CopyFromHelper in the ROME API.
      public void copyFrom(Object syndImage) {
        COPY_FROM_HELPER.copy(this,syndImage);
      }

      private static final CopyFromHelper COPY_FROM_HELPER;

      static {
            Map basePropInterfaceMap = new HashMap();
            basePropInterfaceMap.put("title",String.class);
            basePropInterfaceMap.put("url",String.class);
            basePropInterfaceMap.put("link",String.class);
            basePropInterfaceMap.put("description",String.class);

            Map basePropClassImplMap = Collections.EMPTY_MAP;

            COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class,basePropInterfaceMap,basePropClassImplMap);
      }
}
